#ifndef __LINKTREE_H_
#define __LINKTREE_H_
#include"doubleLinkList.h"
#include"string"
class LinkTree;
class TreeNode//树的结点
{
public:
    using ElementType=void *;
    TreeNode(const ElementType&element);
    //将一个结点绑定成另一个结点的孩子
    void Connect(TreeNode *parent);
    void Disconnect(TreeNode *parent);
    TreeNode *Getparent(){return parent;}
    ElementType GetData(){return data;}
    void setData(const ElementType& element){data=element;}
    friend LinkTree;

private:
    ElementType data;//数据域
    TreeNode *parent;//双亲结点
    TreeNode *firstChild;//第一个孩子指针
    TreeNode *nextSbling;//下一个兄弟指针
    
    void(*Free)(void *);//释放对象的函数指针
    bool(*Compare)(void*,void*);
    bool(*ComBig)(void*,void*);//比较大小指针
    void(*Print)(void *);

};
class LinkTree
{
public:
    using ElementType=TreeNode::ElementType;
       void setfunc (void (*Free)(void*),bool(*Compare)(void*,void*), bool(*ComBig)(void*,void*),void(*Print)(void *))
        {
            this->Free=Free;
            this->Print=Print;
            this->Compare=Compare;
            this->ComBig=ComBig;
        }
    LinkTree();
    ~LinkTree();
    TreeNode *GetRoot(){return root;};

    void show();

    doubleLinkList FindByelement(const ElementType&element);
    //获取树的高度
    int GetTreeHeight();
    //统计树中结点数量
    int Size();
    //统计树中叶子结点数量
    int leafSize();

private:
    void show(TreeNode *node,int deepth);
    void FreeNode(TreeNode *node);
    void FindNode(TreeNode* node , const ElementType& element,doubleLinkList& list);
    int  GetNodeHeight(TreeNode *node);
    void  GetNodeSize(TreeNode *node,int &count);
    void  GetleafSize(TreeNode *node,int &count);
    TreeNode *root;
    void(*Free)(void *);//释放对象的函数指针
    bool(*Compare)(void*,void*);
    bool(*ComBig)(void*,void*);//比较大小指针
    void(*Print)(void *);
};







#endif